package com.yhj.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.yhj.service.AdvancedMediaPlayer;
import com.yhj.service.MediaPlayer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * @author yaohj
 * @date 2025年02月12日 16:31
 */
@Component
public class MediaAdapter implements MediaPlayer {
    @Autowired
    private ApplicationContext applicationContext;

    private AdvancedMediaPlayer advancedMediaPlayer;


    @Override
    public void play(String audioType) {
        if(StringUtils.equals(audioType, "1")){
            Object firstPlayer = applicationContext.getBean("firstPlayer");
            advancedMediaPlayer= (FirstPlayer) firstPlayer;
            advancedMediaPlayer.firstFunction();
        }else {
            Object secondPlayer = applicationContext.getBean("secondPlayer");
            advancedMediaPlayer= (SecondPlayer) secondPlayer;
            advancedMediaPlayer.secondFunction();
        }
    }
}
